/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.latesis.dao.hibernate;

import com.latesis.bean.MensajeBean;
import com.latesis.bean.MovilBean;
import com.latesis.bean.MovilBean;
import com.latesis.dao.MovilDAO;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author acabrera
 */
@Transactional(propagation=Propagation.SUPPORTS)
public class MovilDAOHibernateImpl extends HibernateDaoSupport implements MovilDAO{
    public MovilBean guardar(MovilBean bean) {
         getHibernateTemplate().saveOrUpdate(bean);
         return bean;
    }

    public void borrar(MovilBean bean) {
        getHibernateTemplate().delete(bean);
    }

    public MovilBean buscar(MovilBean bean) {
        return getHibernateTemplate().get(MovilBean.class, bean.getId());
    }

    public List<MovilBean> buscarTodos() {
        return (List<MovilBean>)getHibernateTemplate().find("from MovilBean ");
    }

    public List<MovilBean> buscarCustom(int start, int end) {
        Query q = getSession().createQuery("from MovilBean where estado = 'A' ");
        q.setMaxResults(end-start);
        q.setFirstResult(start);
        return (List<MovilBean>)q.list();
    }

    public int countTotal() {
        Query query = getSession().createQuery("SELECT COUNT(u) FROM MovilBean u");
        Number result = (Number)query.uniqueResult();
        return result.intValue();
    }
}
